package com.googlecode.nacl_optimizer.elf.types;

import com.googlecode.nacl_optimizer.elf.headers.DataEncoding;

// 4 byte
class Elf32b4 {
    private DataEncoding enc;
    int val;

    public Elf32b4(DataEncoding enc, byte[] data) {
        this.enc = enc;
        final int len = 4; 
        if (enc == DataEncoding.ELFDATA2LSB) {
            for(int i=0; i < len; i++) {
                this.val+=(data[i] & 0xFF)<<i*8;
            }
        } else if (enc == DataEncoding.ELFDATA2MSB) {
            for(int i=0; i < len; i++) {
                this.val+=(data[len-i] & 0xFF)<<i*8;
            }
        }
    }

    public Elf32b4(int v) {
        this.val = v;
    }

    public Integer getInteger() {
        return Integer.valueOf(val);
    }

    public DataEncoding getEncoding() {
        return enc;
    }

    @Override
    public String toString() {
        return String.valueOf(getInteger());
    }
}
